﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using TouchSocket.Core;
using TouchSocket.Http;
using TouchSocket.Sockets;

namespace Control.WeSocket
{
    public class SocketHelper
    {
        public HttpService service;
        public SocketHelper(HttpService _service)
        {
            service = _service;
        }
        public async Task StartAsync()
        {
            await service.SetupAsync(new TouchSocketConfig()//加载配置
                       .SetListenIPHosts(7789)
                         .ConfigureContainer(a =>
                           {
                                       a.AddConsoleLogger();
                           })
                         .ConfigurePlugins(a =>
                          {
                              a.UseWebSocket()//添加WebSocket功能
                              .SetWSUrl("/ws")//设置url直接可以连接。
                                 .UseAutoPong();//当收到ping报文时自动回应pong
                              a.Add<WebSocketPlugin>();//自定义插件。
                          }));

            await service.StartAsync();
        }


    }
}
